﻿using AutoMapper;
using GGetTestService.Dto.Classes;
using GGetTestService.Entity;
using GGetTestService.Extension;
using GGetTestService.Repository.UnitOfWork;
using GGetTestService.Services.Base;
using GGetTestService.Services.Interface;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace GGetTestService.Services
{
    public class ClassesService : BaseService<Classes>, IClassesService
    {
        private readonly IUnitOfWork _unitOfWork;
        private readonly IMapper _mapper;

        public ClassesService(IUnitOfWork unitOfWork,IMapper mapper) : base(unitOfWork)
        {
            _unitOfWork = unitOfWork;
            _mapper = mapper;
        }
        public async Task<IEnumerable<ClassesDto>> GetClassesIncludeTeacherAndStudents()
        {
            var _classRepository = _unitOfWork.GetRepository<Classes>();

            var list = await _classRepository.Queryable
                                           .Include(x => x.Teachers)
                                           .Include(x => x.Students)
                                           .AsNoTracking()
                                           .ToListAsync();

            var newList = list.ProjectTo<ClassesDto>(_mapper);
            return newList;


        }
    }
}
